local player_boss = ""
if game.player.faction == "air" then player_boss = "Ariel, Queen of Air, "
elseif game.player.faction == "earth" then player_boss = "Quaker, Master of Earth, "
elseif game.player.faction == "fire" then player_boss = "Vargo, Tyrant of Fire, "
elseif game.player.faction == "water" then player_boss = "Waldern, King of Water, "
end

--[[if npc.faction == "air" then
	boss_art = "boots"
	anti = "earth"
	gender = "She"
	parting_speech = " May the zephyrs carry you swiftly to your journey's end."
elseif npc.faction == "earth" then
	boss_art = "robe"
	anti = "air"
	parting_speech = " May the ground be firm beneath you to your journey's end."
elseif npc.faction == "fire" then
	boss_art = "gloves"
	anti = "water"
	parting_speech = " May the tides carry you safely to your journey's end."
elseif npc.faction == "water" then
	boss_art = "cloak"
	anti = "fire"
	parting_speech = " May those who oppose your journey be consumed."
end
]]

newChat{ id="welcome",
	text = "#WHITE#Welcome @playername@!",
	answers = {
	--	Answer if the player is the same element
		{"Huh? How do you know me?", cond=function(npc, player) if player.faction == "air" then return true end return false end, jump="talk"},
		{"Ariel, while I was on the surface, I talked to an ancient elemental, who was transformed into a spawn of chaos.  However, before he died, he told me something about 'orbs leading the wa..', do you know about these orbs and what purpose they hold?", cond=function(npc, player) if player.faction == "air" and player:isQuestStatus("orb-option", engine.Quest.PENDING) then return true end return false end, action=function(npc,player) player:setQuestStatus("orb-option", engine.Quest.DONE) end, jump="chaos"},
	--	Answers if the player has the orb collection quest
		{"Hello! " .. player_boss .. "sent me here because he feels that it is necessary to talk with the mana elementals as chaos seems to be on the verge of breaking loose into the world.  He thinks that an orb in your safekeeping is key to contacting them, can I borrow it?", cond=function(npc, player) if player.faction ~= "air" and player.faction ~= "mana" and player:isQuestStatus("orb-collection", engine.Quest.PENDING) then return true end return false end, jump="orb",},
		{"I am trying to get back to my realm to talk with Akraad about the incursion of chaos, but I think I need to collect the elemental orbs to activate the portal to my realm! Could I borrow your orb and return it as soon as I can?", cond=function(npc, player) if player.faction == "mana" and player:isQuestStatus("orb-collection", engine.Quest.PENDING) then return true end return false end, jump="thanks",},
	--	Answers if the player does not have to orb collection quest
		{"Hi!", cond=function(npc, player) if player.faction ~= "air" and not player:isQuestStatus("orb-collection", engine.Quest.PENDING) then return true end return false end, },
	}
}

newChat{ id="thanks",
	text = "#LIGHT_GREEN#*She looks troubled* #WHITE#Long have I suspected that chaos was behind this... #LIGHT_GREEN#*She pauses long in thought* #WHITE#I suppose I must let you, go now, the orb is behind me. May the winds carry you swiftly to your journey's end.",
	answers = {
		{"Thanks!", action=function(npc, player) npc:move(34, 2, true) end},
	}
}

newChat{ id="chaos",
	text = "#LIGHT_GREEN#*She looks troubled* #WHITE#For a long time I thought that the wizards themselves were behind this, but now I see that that is not the case. They, in their greed for power have brought chaos into the picture.  I am afraid it is beyond my power to stop chaos, nor any of the other elements here on the surface.  But legend (and a gift) tell of a time when the mana elementals drove chaos back through their portals and then sealed them at a great cost.",
	answers = {
		{"What was the cost?", jump="chaos1"},
	}
}

newChat{ id="chaos1",
	text = "#WHITE#They sacrificed their own portals to lock chaos behind them.  But if it is as you say, chaos is again breaking out, and they must be warned!  Long ago, when I was still young, a mana elemental came to me and brought me an orb... long have I treasured this gift, for it contained the powers of the winds, and also because he gave a warning with it, 'Beware!' he said, 'for if chaos again is seen, you will need our help.  I am giving you one of the keys to unlock our portal, but do not use it unless it is absolutely necessary, for if used, chaos can break out easier.'",
	answers = {
		{"Do you still have this orb? I am afraid the time is come to seek the mana elementals,", jump="chaos2"},
	}
}

newChat{ id="chaos2",
	text = "#WHITE#I suppose you are right.  The orb itself is behind me, guarded well, take it, and bring a message to all the other leaders of the elements, warning them of our true foe.  We must stop bickering and infighting, which chaos revels in, but join together and seek out the leader of the mana elementals for their help. I am sure he knows what we must do! May the winds carry you swiftly to your journey's end.",
	answers = {
		{"Thanks! I shall do my best.", action=function(npc, player)
			player:grantQuest("orb-collection")
			engine.Faction:setFactionReaction("air", "earth", 0, true)
			npc:move(34, 2, true)
			local o, item, inven_id = npc:findInAllInventories("Winged Boots")
			if o and item and inven_id then
				npc:removeObject(inven_id, item, true)
				player:addObject(player.INVEN_INVEN, o)
				player:sortInven()
				game.logPlayer(player, "Ariel gives you %s, and steps out of your way.", o:getName{do_color=true})
			end
		end},
	}
}

newChat{ id="talk",
	text = "#WHITE#*Sigh* Those wizards never portal correctly! Now you got amnesia. Anyways, could you do me a favor? I will loan you my boots and the air orb if you succeed!",
	answers = {
		{"Sure!", jump="talk1"},
		{"Just a second, while I was on the surface, I talked to an ancient elemental, who was transformed into a spawn of chaos.  However, before he died, he told me something about 'orbs leading the wa..', do you know about these orbs and what purpose they hold?", cond=function(npc, player) if player.faction == "air" and player:isQuestStatus("orb-option", engine.Quest.PENDING) then return true end return false end, action=function(npc,player) player:setQuestStatus("orb-option", engine.Quest.DONE) end, jump="chaos"},
		{"Sorry, I am busy."},
	}
}

newChat{ id="talk1",
	text = [[#WHITE#Thanks! I would like you to go over and defeat the earth elementals.  They have started quarreling with us since, well, the wizards arrived.  Show them that air elementals are stronger!]],
	answers = {
	{"Ok!", action=function(npc, player)
		player:grantQuest("destroy-earth")
	end}
	}
}

newChat{ id="quest",
	text = [[#WHITE#Thanks! The Orb of Air is past me.]],
	answers = {
		{"Ok!", action=function(npc, player)
			player:setQuestStatus("destroy-earth", engine.Quest.DONE)
			npc:move(34, 2, true)
			local o, item, inven_id = npc:findInAllInventories("Winged Boots")
			if o and item and inven_id then
				npc:removeObject(inven_id, item, true)
				player:addObject(player.INVEN_INVEN, o)
				player:sortInven()
				game.logPlayer(player, "Ariel gives you %s, and steps out of your way.", o:getName{do_color=true})
			end
		end}
	}
}

newChat{ id="orb",
	text = "#WHITE#What you say is most distressing! #LIGHT_GREEN#*She ponders for a while* #WHITE#I suppose I must let you borrow this, but know this, I have never let an air elemental, let alone a " .. game.player.faction .. " elemental even touch this.  If you lose it, I will go after you with a vengence!",
	answers = {
		{"#LIGHT_GREEN#*Gulp!* #WHITE# I will guard it with my life!", action=function(npc, player) npc:move(34, 2, true) end, jump="orb1",}
	}
}

newChat{ id="orb1",
	text = "#WHITE#Go then! The orb is behind me and well guarded, but you need not fear.",
	answers = {
		{"Thanks, and farewell milady!"}
	}
}

newChat{ id="waiting",
	text = [[#WHITE#Have you destroyed the earth temple yet?]],
	answers = {
		{"Errrr.... I am still working in it"},
		{"Just a second, while I was on the surface, I talked to an ancient elemental, who was transformed into a spawn of chaos.  However, before he died, he told me something about 'orbs leading the wa..', do you know about these orbs and what purpose they hold?", cond=function(npc, player) if player.faction == "air" and player:isQuestStatus("orb-option", engine.Quest.PENDING) then return true end return false end, action=function(npc,player) player:setQuestStatus("orb-option", engine.Quest.DONE) player:setQuestStatus("destroy-earth", engine.Quest.FAILED) end, jump="chaos"},
	}
}

newChat{ id="hi",
	text = "#WHITE#Hi!",
	answers = {
		{"Hi!"}
	}
}

if game.player:isQuestStatus("destroy-earth", engine.Quest.COMPLETED) then
	return "quest"
elseif game.player:isQuestStatus("destroy-earth", engine.Quest.DONE) then
	return "hi"
elseif game.player:isQuestStatus("destroy-earth", engine.Quest.PENDING) then
	return "waiting"
else
	return "welcome"
end
